package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {
	
	private CategoryService categoryService;
	
	public CategoryController(CategoryService categoryService) {
		this.categoryService = categoryService;
	}
	
	@PostMapping
	public Result insert(@RequestBody CategoryDTO categoryDTO) {
		return categoryService.insert(categoryDTO);
	}
	
	@GetMapping("/page")
	public Result<PageResult> page(CategoryPageQueryDTO pageQueryDTO) {
		return categoryService.page(pageQueryDTO);
	}
	
	@DeleteMapping
	public Result deleteById(Long id) {
		return categoryService.deleteById(id);
	}
	
	@PutMapping
	public Result update(@RequestBody CategoryDTO categoryDTO) {
		return categoryService.update(categoryDTO);
	}
	
	@PostMapping("/status/{status}")
	public Result banCategory(@PathVariable Integer status, Long id) {
		return categoryService.banCategory(status, id);
	}
	
	@GetMapping("/list")
	public Result getListByType(Integer type) {
		return categoryService.getListByType(type);
	}
}
